const user = {
  state: {
    userId: '',
    username: '',
    industry: '',
    description: '',
    qq: '',
    wechat: ''
  },
  getters: {
    userId: state => {
      let userId = state.userId
      if (!userId) {
        userId = JSON.parse(localStorage.getItem('userId') || null)
      }
      return userId
    },
    username: state => {
      let username = state.username
      if (!username) {
        username = JSON.parse(localStorage.getItem('username') || null)
      }
      return username
    },
    industry: state => {
      let industry = state.industry
      if (!industry) {
        industry = JSON.parse(localStorage.getItem('industry') || null)
      }
      return industry
    },
    description: state => {
      let description = state.description
      if (!description) {
        description = JSON.parse(localStorage.getItem('description') || null)
      }
      return description
    },
    qq: state => {
      let qq = state.qq
      if (!qq) {
        qq = JSON.parse(localStorage.getItem('qq') || null)
      }
      return qq
    },

    wechat: state => {
      let wechat = state.wechat
      if (!wechat) {
        wechat = JSON.parse(localStorage.getItem('wechat') || null)
      }
      return wechat
    }
  },
  mutations: {
    setUserId: (state, userId) => {
      state.userId = userId
      localStorage.setItem('userId', JSON.stringify(userId))
    },
    removeUserId: (state) => {
      state.userId = ''
      localStorage.setItem('userId', '')
    },
    setUsername: (state, username) => {
      state.username = username
      localStorage.setItem('username', JSON.stringify(username))
    },
    removeUsername: (state) => {
      state.username = ''
      localStorage.setItem('username', '')
    },
    setIndustry: (state, industry) => {
      state.industry = industry
      localStorage.setItem('industry', JSON.stringify(industry))
    },
    removeIndustry: (state) => {
      state.industry = ''
      localStorage.setItem('industry', '')
    },
    setDescription: (state, description) => {
      state.description = description
      localStorage.setItem('description', JSON.stringify(description))
    },
    removeDescription: (state) => {
      state.description = ''
      localStorage.setItem('description', '')
    },
    setQQ: (state, qq) => {
      state.qq = qq
      localStorage.setItem('qq', JSON.stringify(qq))
    },
    removeQQ: (state) => {
      state.qq = ''
      localStorage.setItem('qq', '')
    },
    setWechat: (state, wechat) => {
      state.wechat = wechat
      localStorage.setItem('wechat', JSON.stringify(wechat))
    },
    removeWechat: (state) => {
      state.wechat = ''
      localStorage.setItem('wechat', '')
    }
  },
  actions: {}
}

export default user
